package Crawler;

import org.apache.commons.io.FileUtils;
import redis.clients.jedis.Jedis;

import javax.print.DocFlavor;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class arrayListRedis {

    private static Jedis jedis = new Jedis("222.27.227.115", 6379);

    // 主函数
    public static void main(String[] args) throws IOException {

        //连接本地的 Redis 服务
        System.out.println("SUCCEED!");


        // 从文件中读取数据然后存入redis中
        String fileName = "C:/Users/TING/code/java code/Weibo/RedisDemo.txt";
        ArrayList lineList = new ArrayList();
        lineList = getUidList(fileName);
        for (int i = 0; i < lineList.size(); i++) {
            String line = lineList.get(i).toString();
            jedis.lpush("w:demo", line);
            System.out.println("已成功将     " + line + "    加入队列");
        }

        String line = getUidAndConnumIntoRedis();
        System.out.println(line);


    }


    // 连接Redis,从中获取uid以及Connum
    public static String getUidAndConnumIntoRedis() {

        // 从Redis中获取数据并出队，uid以及connum要分开
        // 不能用队列一次取出，只能取出一个然后销毁
        String element = jedis.lpop("w:demo");
        System.out.println("当前使用了: " + element);
        System.out.println("现出队--------------------" + element);
        return element;
}

    public static ArrayList getUidList(String fileName) {
        ArrayList uidList = new ArrayList();
        try {
            for (String line : FileUtils.readLines(new File(fileName))) {
                uidList.add(line);
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return uidList;
    }
}

